package com.frx.leetoffer.subset;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：frx
 * @date ：Created in 2019/10/31 20:00
 * @description：ToDO
 * @modified By：
 * @version: ToDO
 */
public class ChildSet {

    public static void main(String[] args){
        int[] arr = {1,2,5,8};
        for (int i=0;i<Math.pow(2,arr.length) - 1;i++){
            get(i,arr);
        }
        System.out.println(list.toString());
    }


    static List<String> list = new ArrayList<>();
    public static void get(int x,int[] mm){
        String sum = "";
        String m = getBinaryValue(x,mm.length);
        char[] data = m.toCharArray();
        for (int i=0;i<data.length;i++){
            if (data[i] == '1'){
                sum+=mm[i];
            }
        }
        if (!sum.equals("")){
            list.add(sum);
        }

    }

    public static String getBinaryValue(int x,int n){
        StringBuffer sb = new StringBuffer(Integer.toBinaryString(x));
        System.out.println(sb.toString());
        int length = sb.length();
        for (int j=0;j<n - length;j++){
            sb.insert(0,"0");
        }
        /*System.out.println(sb);*/
        return sb.toString();
    }

}
